<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>新闻查看</title>
<style type="text/css">
/*新闻展示样式*/
.news_show{ margin:0 auto;}
.news_show .show_title {text-align:center; font-size:14px; border-bottom:1px dotted #c7c7c7; padding-bottom:15px;margin-bottom:20px;}
.news_show h2{ font-size:24px;}
.news_show span{ padding-right:10px;}
.news_show .paging{ text-align:center;}
.news_show a{ color:#0871A5;}
.news_show .content{font-size:15px;text-indent:28px;}
.news_show .operator{padding-top:25px; text-align:center; }
</style>
<script src="../common/jquery-3.1.1.min.js" type="text/javascript"></script>
</head>
<?php
   require_once '../common/news.dao.php';
   require_once '../common/newsclass.dao.php';
   require_once '../common/user.dao.php';
   if(isset($_GET['newsid'])){
        $newsid=$_GET['newsid'];
		$rst=findNewsById($newsid);
		$author_rst=findUserById($rst['uid']);
        $author=$author_rst['uname'];
		$newsclass_rst=findNewsClassById($rst['classid']);		
		$newsclass=$newsclass_rst['classname']; 
		//更新新闻访问量
		$viewcount=$rst['viewcount']+1;
		$result=updateViewCount($newsid);
		if(!$result){echo "<script>alert('fail update viewcount.');</script>";}
		
		//点赞相关
		$likecount=$rst['likecount'];
       
   }else{
	  header("location:newslist.php");     
   }
?>
<body>
    <div class="news_show">
		<div class="show_title"> 
			<h2><?php echo $rst['title'];?></h2>
			<span>时间：<?php echo $rst['publishtime'];?></span>
			<span>分类：<?php echo $newsclass;?></span>
			<span>作者：<?php echo $author;?></span>
            <span>访问量：<?php echo $viewcount;?></span>            
		</div>
		<div class="content"><?php echo htmlspecialchars_decode(trim($rst['content']));?> </div>
       <div class="operator">
              <button id="vote"  rel="<?php echo $newsid;?>">点赞</button> 
              <span id="likes"><?php echo $likecount;?></span>
        </div>
       	
	</div>
   
   <script type="text/javascript">
     $(document).ready(function() {
         $("#vote").click(function(){		   
	      $.ajax({ 
		     url:"updatelike.php",//处理数据的地址
             type:"post",//数据提交形式
             data:{"id":<?php echo $newsid;?>,"likecount":<?php echo $likecount;?> },//需要提交的数据
             success:function(data){//数据返回成功的执行放大
             if(data==false){
				 alert("赞过了");     
			 }else{
			    alert('点赞数+1');				
				$("#likes").html(data);
			 }               	 
	       }
	    });	 
     });
   });
   </script>
  
</body>
</html>